home *** CD-ROM | disk | FTP | other *** search
- Path: news.tu-chemnitz.de!news
- From: hfst@hrz.tu-chemnitz.de (Hans Steffani)
- Newsgroups: comp.lang.c
- Subject: Re: Returning a variable from system() function
- Date: 19 Jan 96 15:02:28 GMT
- Organization: University of Technology Chemnitz, FRG
- Message-ID: <4doc5c$aet@pyrrhus-f.hrz.tu-chemnitz.de>
- References: <295336694wnr@iiga.demon.co.uk>
- NNTP-Posting-Host: mmu.hrz.tu-chemnitz.de
-
- Pete Ryan <pete@iiga.demon.co.uk> writes:
-
- >#include <stdio.h>
- >#include <stdlib.h>
-
- >void main()
- >{
- > char tmp[];
- >
- > chdir("/usr2/willesden");
- >
- > */ offending code below ;( */
- > tmp = system("find . -name gwire");
-
- > printf("%s",tmp");
-
- >}
-
- >Therefore if I run `find . -name gwire -print` it returns all the
- >directories containing `gwire`. However the code above does not
- >work!!. Is it because `= system` returns an integer and not strings???
-
- >Any help would be very much appreciated as I have only just started
- >learning c in the last 2 months.
-
- Reading the manual, you find out that system() returns the exit state
- of the shell which is hopefully 0.
- Perhaps.
- tmp = system("find . -name gwire > tmp_datei.tmp");
- and inspecting tmp_datei.tmp afterwards (if tmp==0) can solve your
- problem.
-
- You also should change the definition of tmp to
- int tmp;
-
- You also should change main() to
- int main()
-
- h.f.s.
- h.f.s.
- --
- Hans Friedrich Steffani
- Institut fuer Elektrische Maschinen und Antriebe
- TU Chemnitz-Zwickau
- e-mail: hans.steffani@e-technik.tu-chemnitz.de
-